package org.lds.message.center.alipay.autoconfigure;

import lombok.RequiredArgsConstructor;
import org.lds.message.center.alipay.AlipayHandler;
import org.lds.message.center.alipay.AlipayMessageService;
import org.lds.message.center.alipay.constant.AlipayConstant;
import org.lds.message.center.alipay.consumer.AlipayConsumer;
import org.lds.message.center.alipay.health.endpoint.AlipayHealthEndpoint;
import org.lds.message.center.alipay.properties.AlipayProperties;
import org.lds.message.center.alipay.starter.AlipayRegisterAdmin;
import org.lds.message.center.plugin.core.kafka.KafkaProducer;
import org.lds.message.center.plugin.core.remote.RemoteService;
import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
import org.springframework.boot.context.properties.EnableConfigurationProperties;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

@Configuration
@RequiredArgsConstructor
@ConditionalOnProperty(prefix = AlipayConstant.ALIPAY_PREFIX, name = "enabled", havingValue = "true")
@EnableConfigurationProperties({AlipayProperties.class})
public class AlipayMessageAutoConfiguration {
    private final AlipayProperties alipayProperties;

    @Bean
    public AlipayMessageService alipayMessageService(KafkaProducer kafkaProducer, AlipayHandler alipayHandler) {
        return new AlipayMessageService(alipayHandler, alipayProperties, kafkaProducer);
    }

    @Bean
    public AlipayHandler alipayHandler() {
        return new AlipayHandler(alipayProperties);
    }

    @Bean
    public AlipayConsumer alipayConsumer(AlipayMessageService alipayMessageService) {
        return new AlipayConsumer(alipayMessageService);
    }

    @Bean
    public AlipayRegisterAdmin alipayRegisterAdmin(RemoteService remoteService) {
        return new AlipayRegisterAdmin(remoteService);
    }

    @Bean
    public AlipayHealthEndpoint alipayHealthEndpoint() {
        return new AlipayHealthEndpoint();
    }

}
